IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[or_MentorTagInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.[or_MentorTagInsert]
Go

CREATE  PROCEDURE  dbo.[or_MentorTagInsert]  
	@UserID  int,
	@TagsCSL nvarchar(1000)
	--[or_MentorTagUpdate] 7, '1,2,4'

AS  
  
  declare @DateTime datetime,@TranCountAtEntry int
  select @DateTime = getdate() 
BEGIN TRY 

IF @TranCountAtEntry  = 0 
BEGIN TRANSACTION 

Delete from dbo.UserMentorTag where MeMaUserID = @UserID

INSERT INTO UserMentorTag
select @UserID, *, GETDATE(), GETDATE() from or_fnSplitCSV(@TagsCSL, ',')


 
IF @@TRANCOUNT > @TranCountAtEntry
COMMIT TRANSACTION

END TRY
BEGIN CATCH
  
  IF @@TRANCOUNT > @TranCountAtEntry
  ROLLBACK TRANSACTION

  -- Raise an error with the details of the exception
  or_raiseerror 

END CATCH
  
  